package com.yanqu.road.server.logic.activity.condition.hotpotjump;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.autodata.hotpotjump.UserHotpotJumpData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jumppot.HotpotJumpModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;

import java.math.BigInteger;

public class HotpotJumpScoreRankCondition extends BaseNewRankActivityCondition {
    public HotpotJumpScoreRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        UserHotpotJumpData userData = player.getModule(HotpotJumpModule.class).getUserData();
        if (userData == null) {
            return;
        }
        if (userData.getActivityId() != activityInfo.getActivityId()) {
            return;
        }
        int newScore = userData.getScore();
        int maxRound = userData.getMaxRound();
        if (newScore > getValue().intValue() || (newScore == getValue().intValue() && maxRound < Integer.valueOf(getParam()))) {
            setValue(BigInteger.valueOf(newScore));
            setParam(String.valueOf(maxRound));
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.HotpotJumpScoreRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.HotpotJumpScoreRank.getValue(), handle);
    }

    @Override
    public boolean canChange(ActivityInfo activityInfo) {
        if (ActivityMgr.activityInTime(activityInfo)) {
            return true;
        }
        return false;
    }
}
